#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> arr(n + 1);

    for (int i = 1; i <= n; i++)
        cin >> arr[i];

    ll ret = -0x3f3f3f3f;
    ll cur = 0;
    for (int i = 1; i <= n; i++) {
        cur += arr[i];
        ret = max(ret, cur);
        cur = max(cur, (ll)0);
    }
    cout << ret << endl;
    return 0;
}
